home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2 Examples.sit / Raven 1.2 Examples / Quill / Source / CheckedHelpEditor.cpp < prev    next >
Text File  |  1997-08-10  |  6KB  |  243 lines

  1. /*
  2.  *  File:       CheckedHelpEditor.cpp
  3.  *  Summary:       A view that knows how to edit a control's checked help message.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <2>     4/06/97    JDJ        Updated for new style TSubPaneIterator.
  12.  *         <1>     2/05/97    JDJ        Created
  13.  */
  14.  
  15. #include "CheckedHelpEditor.h"
  16.  
  17. #include <ZRadioButton.h>
  18. #include <ZStaticText.h>
  19. #include <ZStringUtils.h>
  20. #include <ZTextBox.h>
  21.  
  22.  
  23. // ===================================================================================
  24. //    class CEditCheckedHelpCommand
  25. // ===================================================================================
  26.  
  27. //---------------------------------------------------------------
  28. //
  29. // CEditCheckedHelpCommand::~CEditCheckedHelpCommand
  30. //
  31. //---------------------------------------------------------------
  32. CEditCheckedHelpCommand::~CEditCheckedHelpCommand()
  33. {
  34. }
  35.  
  36.  
  37. //---------------------------------------------------------------
  38. //
  39. // CEditCheckedHelpCommand::CEditCheckedHelpCommand
  40. //
  41. //---------------------------------------------------------------
  42. CEditCheckedHelpCommand::CEditCheckedHelpCommand(TControl* pane, const SControlInfo& oldInfo, const SControlInfo& newInfo) : Inherited(pane, oldInfo, newInfo)
  43. {
  44. }
  45.  
  46.  
  47. //---------------------------------------------------------------
  48. //
  49. // CEditCheckedHelpCommand::UpdatePane
  50. //
  51. //---------------------------------------------------------------
  52. void CEditCheckedHelpCommand::UpdatePane(const SControlInfo& info)
  53. {
  54.     mPane->SetCheckedHelpMessage(info.checkedMesg);
  55. }
  56.  
  57. #pragma mark -
  58.  
  59. // ===================================================================================
  60. //    CCheckedHelpEditor
  61. // ===================================================================================
  62.  
  63. static TReanimatorRegister<CCheckedHelpEditor> sCheckedHelpEditorRegistrar;
  64.  
  65. //---------------------------------------------------------------
  66. //
  67. // CCheckedHelpEditor::~CCheckedHelpEditor
  68. //
  69. //---------------------------------------------------------------
  70. CCheckedHelpEditor::~CCheckedHelpEditor()
  71. {
  72. }
  73.  
  74.  
  75. //---------------------------------------------------------------
  76. //
  77. // CCheckedHelpEditor::CCheckedHelpEditor
  78. //
  79. //---------------------------------------------------------------
  80. CCheckedHelpEditor::CCheckedHelpEditor(TView* superView) : Inherited(superView)
  81. {
  82.     mType = '????';
  83. }
  84.  
  85.  
  86. //---------------------------------------------------------------
  87. //
  88. // CCheckedHelpEditor::Create                            [static]
  89. //
  90. //---------------------------------------------------------------
  91. MReanimatable* CCheckedHelpEditor::Create(MReanimatable* parent)
  92. {
  93.     return new CCheckedHelpEditor(dynamic_cast<TView*>(parent));
  94. }
  95.  
  96.  
  97. //---------------------------------------------------------------
  98. //
  99. // CCheckedHelpEditor::OnReanimated
  100. //
  101. //---------------------------------------------------------------
  102. void CCheckedHelpEditor::OnReanimated()
  103. {
  104.     Inherited::OnReanimated();
  105.     
  106.     TSubPaneIterator iter = this->begin();
  107.     while (iter != this->end()) {
  108.         TPane* pane = *iter;
  109.         ++iter;
  110.         
  111.         if (TRadioButton* button = dynamic_cast<TRadioButton*>(pane))
  112.             button->AddListener(this);
  113.     }
  114. }
  115.  
  116.  
  117. //---------------------------------------------------------------
  118. //
  119. // CCheckedHelpEditor::OnBroadcast
  120. //
  121. //---------------------------------------------------------------
  122. void CCheckedHelpEditor::OnBroadcast(const SControlMessage& mesg)
  123. {
  124.     if (mesg.value == 1) {
  125.         mType = StrToID(mesg.message);
  126.         
  127.         this->TogglePanes();
  128.     }
  129. }
  130.  
  131.  
  132. //---------------------------------------------------------------
  133. //
  134. // CCheckedHelpEditor::TogglePanes
  135. //
  136. //---------------------------------------------------------------
  137. void CCheckedHelpEditor::TogglePanes()
  138. {
  139.     TStaticText* caption = dynamic_cast<TStaticText*>(this->FindSubPane("ID Caption"));
  140.     
  141.     if (mType == 'STRL') {
  142.         caption->Hide();
  143.         
  144.         this->FindSubPane("String Literal")->Show();
  145.         this->FindSubPane("Rsrc ID")->Hide();
  146.         
  147.     } else {
  148.         caption->SetText("Rsrc ID:");
  149.  
  150.         this->FindSubPane("String Literal")->Hide();
  151.         this->FindSubPane("Rsrc ID")->Show();
  152.     }
  153.  
  154.     if (mType == 'STR#') {
  155.         this->FindSubPane("Index Caption")->Show();
  156.         this->FindSubPane("STR# Index")->Show();
  157.         
  158.     } else {
  159.         this->FindSubPane("Index Caption")->Hide();
  160.         this->FindSubPane("STR# Index")->Hide();
  161.     }
  162. }
  163.  
  164.  
  165. //---------------------------------------------------------------
  166. //
  167. // CCheckedHelpEditor::GetEditorInfo        
  168. //
  169. //---------------------------------------------------------------
  170. SControlInfo CCheckedHelpEditor::GetEditorInfo() const
  171. {
  172.     SControlInfo info;
  173.     
  174.     TTextBox* id = dynamic_cast<TTextBox*>(this->FindSubPane("Rsrc ID"));
  175.  
  176.     switch (mType) {
  177.         case 'STR ':
  178.         case 'TEXT':
  179.         case 'PICT':
  180.             info.checkedMesg = THelpMessage(mType, id->GetValue());
  181.             break;
  182.  
  183.         case 'STR#':
  184.             TTextBox* index = dynamic_cast<TTextBox*>(this->FindSubPane("STR# Index"));
  185.             info.checkedMesg = THelpMessage(mType, id->GetValue(), index->GetValue());
  186.             break;
  187.  
  188.         case 'STRL':
  189.             TTextBox* str = dynamic_cast<TTextBox*>(this->FindSubPane("String Literal"));
  190.             info.checkedMesg = THelpMessage(str->GetText());
  191.             break;
  192.             
  193.         default:
  194.             DEBUGSTR("CCheckedHelpEditor::GetHelpMesg had a bogus type.");
  195.     }
  196.     
  197.     return info;
  198. }
  199.  
  200.  
  201. //---------------------------------------------------------------
  202. //
  203. // CCheckedHelpEditor::SetEditorInfo
  204. //
  205. //---------------------------------------------------------------
  206. void CCheckedHelpEditor::SetEditorInfo(const SControlInfo& info)
  207. {
  208.     mType = info.checkedMesg.GetType();
  209.     
  210.     TTextBox* id = dynamic_cast<TTextBox*>(this->FindSubPane("Rsrc ID"));
  211.  
  212.     switch (mType) {
  213.         case 'STR ':
  214.         case 'TEXT':
  215.         case 'PICT':
  216.             id->SetValue(info.checkedMesg.GetID());
  217.             break;
  218.  
  219.         case 'STR#':
  220.             TTextBox* index = dynamic_cast<TTextBox*>(this->FindSubPane("STR# Index"));
  221.             id->SetValue(info.checkedMesg.GetID());
  222.             index->SetValue(info.checkedMesg.GetIndex());
  223.             break;
  224.  
  225.         case 'STRL':
  226.             TTextBox* str = dynamic_cast<TTextBox*>(this->FindSubPane("String Literal"));
  227.             str->SetText(info.checkedMesg.GetStringLiteral());
  228.             break;
  229.             
  230.         default:
  231.             DEBUGSTR("CCheckedHelpEditor::SetHelpMesg had a bogus type.");
  232.     }
  233.     
  234.     TRadioButton* button = dynamic_cast<TRadioButton*>(this->FindSubPane(IDToStr(mType)));
  235.     if (button != nil)    
  236.         button->SetValue(1);
  237.         
  238.     this->TogglePanes();
  239. }
  240.  
  241.  
  242.  
  243.